package com.woniu.project.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.project.core.domain.ProductEntityIdentify;
import com.woniu.project.dao.ProductEntityIdentifyMapper;
import com.woniu.project.dto.identifydto.IdentifyDto;
import com.woniu.project.params.identifyparams.IdentifyConditionParams;
import com.woniu.project.params.identifyparams.IdentifyParams;
import com.woniu.project.service.IProductEntityIdentifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.project.service.IProductEntityService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WHF
 * @since 2020-10-13
 */
@Service
public class ProductEntityIdentifyServiceImpl extends ServiceImpl<ProductEntityIdentifyMapper, ProductEntityIdentify> implements IProductEntityIdentifyService {

    @Autowired
    private ProductEntityIdentifyMapper productEntityIdentifyMapper;
    @Autowired
    private IProductEntityService productEntityService;

    @Override
    public IPage<IdentifyDto> selectIdentityList(IdentifyConditionParams identifyConditionParams) {
        Page<IdentifyDto> page=new Page<>(identifyConditionParams.getPageIndex(),identifyConditionParams.getPageNumber());
        IPage<IdentifyDto> identifyDtoIPage=productEntityIdentifyMapper.selectIdentityList(page,identifyConditionParams.getProductEntityId());
        return identifyDtoIPage;
    }

    @Override
    public void deleteIdentity(Integer productEntityId) {
        productEntityIdentifyMapper.deleteIdentity(productEntityId);
    }

    @Override
    public void insertIdentity(IdentifyParams identifyParams) {
        ProductEntityIdentify productEntityIdentify=new ProductEntityIdentify();
        BeanUtils.copyProperties(identifyParams,productEntityIdentify);
        productEntityIdentify.setProductEntityIdentifyTime(new Date());
        save(productEntityIdentify);
        productEntityService.updateIdentity(identifyParams.getProductEntityId(),identifyParams.getIdentifyManId());
    }
}
